'use strict';
//////////////////////////////////////////////////////////////////////////////
// 全局存储
//////////////////////////////////////////////////////////////////////////////
function $mock () {
    function http(option){
        var param = angular.extend({}, {
            url: null,
            method: "GET",// 默认get方式请求
            params: null,
            data: null,
            dataType: 'json',
            cache: false,// get请求时候，是否开启缓存，启用缓存，AngularJS默认会使用$cacheFactory,这个服务是AngularJS在启动时自动创建的。
            timeout: 12e3// 超时时间
        }, option);
        return new Promise((resolve, reject) => {
            var cb = function(data){
                console.log('mock', data)
                resolve({status:200, data: data})
            };
            if(param.url == '/api/Allot/IncomeB2TBList'){
                var mock = {
                    "code": 200,
                    "msg":"",
                    "data": {
                        "list": [],
                        "rowcount": 0,
                        "sumDate": {}
                    }
                };
                var Random = Mock.Random;
                var x = Random.integer(1, 100);
                var pagecount = ( x > 10 ) ? 10 : x;
                var rowcount = ( x > 10 ) ? 90 : x;
                for(var i = 0, l = pagecount; i < l; i++){
                    mock.data.list.push({
                        "date": Random.date('yyyy-MM-dd'),
                        "archiveDate": Random.date('yyyy-MM-dd'),
                        "userName": Random.cname(),
                        "bizName": Random.cparagraph(1),
                        "adId": Random.natural(1, 10000),
                        "url": Random.url(),
                        "uvCount": Random.natural(1, 10000),
                        "uvAdjustCount": Random.natural(1, 10000),
                        "price": Random.float(1, 10000, 2, 2),
                        "amount": Random.float(1, 10000, 2, 2),
                        "xxx": Random.float(1, 10000, 2, 2),
                        "incomeType": Random.integer(0, 2),
                        "archiveState": Random.integer(0, 1),
                        "splitState": Random.integer(0, 2)
                    })
                }
                mock.data.rowcount = rowcount;
                (function(){
                    mock.data.sumDate = {
                        "uvCountSum": Random.natural(1, 10000),
                        "uvAdjustCountSum": Random.natural(1, 10000),
                        "amountSum": Random.float(1, 10000, 2, 2)
                    }
                })()
                return cb(mock);
            }
            if(param.url == '/api/customer/getlistMock'){
                var mock = { "code": 200, "msg":"", "data": [ {"id": 11, "name": "假数据1"}, {"id": 21, "name": "假数据2"}, {"id": 31, "name": "假数据3"}, {"id": 41, "name": "假数据4"}, {"id": 51, "name": "假数据5"}, {"id": 61, "name": "假数据6"} ] };
                return cb(mock);
            }
            if(param.url == '/api/busi/typelist22'){
                var mock = { "code": 200, "msg":"", "data": [ {"id": 11, "name": "假数据1"}, {"id": 21, "name": "假数据2"}, {"id": 31, "name": "假数据3"}, {"id": 41, "name": "假数据4"}, {"id": 51, "name": "假数据5"}, {"id": 61, "name": "假数据6"} ] };
                return cb(mock);
            }
            if(param.url == '/api/customer/GetManager'){
                var mock = {"code":200,"msg":"","data":{"list":[{"id":3,"name":"aa"},{"id":145,"name":"yy"},{"id":146,"name":"ii"}]}};
                return cb(mock);
            }
            if(param.url == '/api/user/info'){
                var mock = {"code":200,"msg":"","data":{"username":"xianJs666","sex":"1","powerlist":[11, 12, 13, 14, 15, 16, 17, 171, 172, 18, 181, 19, 191, 20, 21]}};
                return cb(mock);
            }
            if(param.url == '/api/monitor/cnzz_detail'){
                var mock = {"code":200,"msg":"","data":{"adids":[{"userId":3242,"bizName":"页游","userName":"bq2097001","adid":93,"adName":"cead(93)"}],"remark":null}};
                return cb(mock);
            }
            if(param.url == '/api/customer/getlist'){
                var mock = {"code":200,"msg":"","data":[{"I":1,"N":"aaa(张恒)","BizId":68},{"I":1769,"N":"hbxf1(王建英)","BizId":3}]};
                return cb(mock);
            }
            if(param.url == '/api/business/get_B2class_busi'){
                var mock = {"code":200,"msg":"","data":[{"id":128,"name":"下载器"},{"id":203,"name":"TF"},{"id":204,"name":"SF"},{"id":208,"name":"TB"},{"id":209,"name":"页游"}]};
                return cb(mock);
            }
            if(param.url == '/api/monitor/cnzz_biz_adid'){
                var mock = {"code":200,"msg":"","data":[{"id":93,"name":"cead(93)"}]};
                return cb(mock);
            }
            if(param.url == 'cardfromDetail') {
                var mock = {
                    'code': 200,
                    'msg':'',
                    'data': {
                    }
                };
                var Random = Mock.Random;
                mock.data = {
                    'username': Random.cname(),
                    'account': Random.cparagraph(1),
                    'rote': Random.natural(1, 10000),
                    'lotteryDate': Random.date('yyyy-MM-dd'),
                    'money': Random.natural(1, 10000),
                    'price': Random.natural(1, 10000),
                    'lotteryType': Random.integer(0, 1),
                    'lotteryType2': Random.integer(0, 1),
                    'note': Random.cparagraph(1),
                    'isotherget': Random.integer(0, 1),
                    'ismeget': Random.integer(0, 1),
                    'gettype': Random.integer(0, 2),
                    'donatewho': Random.integer(0, 2)
                }
                return cb(mock);
            }
            if(param.url == 'lotteryListApi') {
                var mock = { 'code': 200, 'msg':'', 'data': [ {'id': 11, 'name': '假数据1'}, {'id': 21, 'name': '假数据2'}, {'id': 31, 'name': '假数据3'}, {'id': 41, 'name': '假数据4'}, {'id': 51, 'name': '假数据5'}, {'id': 61, 'name': '假数据6'} ] };
                return cb(mock);
            }
            if(param.url == '/api/test/200f') {
                var mock = { 'code': 200, 'msg':'', 'data': { 'res_code': 0, 'res': '反正就是不对'} };
                return cb(mock);
            }
            if(param.url == '/api/test/200s') {
                var mock = { 'code': 200, 'msg':'', 'data': { 'res_code': 1, 'res': ''} };
                return cb(mock);
            }
            if(param.url == '/api/test/500') {
                var mock = { 'code': 500, 'msg':'服务器炸了' };
                return cb(mock);
            }
            if(param.url == '/api/test/400') {
                var mock = { 'code': 400, 'msg':'敏感词报警..' };
                return cb(mock);
            }
            cb({ "code": 200, "msg":"", "data": null });
        });
    }
    this.$get = function(){ return http };
}
exports = module.exports = $mock;
